<template>
  <!-- 评分等级 -->
  <div class="creditcard" v-if="boolobox">
    <div class="top_bar">
      <div class="left">
        <!-- 搜索框 -->
        <el-input
          v-model="input4"
          class="w-50 m-2"
          placeholder="请输入要查询的评分等级名称"
        >
          <template #prefix>
            <el-icon class="el-input__icon"><search /></el-icon>
          </template>
        </el-input>
        <el-button type="primary" class="zhuangtai btn" @click="dengjichaxun"
          >查询</el-button
        >
        <el-button class="zhuangtai btn btn1">重置</el-button>
      </div>
      <div class="right" @click="dialogFormVisible = true">
        <el-button class="zhuangtai btn btn1" @click="addbtn"
          ><el-icon><Plus /></el-icon>新增</el-button
        >
      </div>
    </div>

    <!-- 表格 -->
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="caGradeid" label="序号" width="180">
        <!-- 组件插槽 -->
        <template #default="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="caGradename" label="评分卡名称" width="180" />
      <el-table-column prop="caState" label="状态" >
        <template #default="scope">
        {{ scope.row.caState==1?"启用":"禁用" }}
      </template>
      </el-table-column>
      <el-table-column prop="caozuo" label="操作">
        <template #default="scope">
          <!-- <el-button type="danger" @click="handleDelete(scope.row.adminid)">Delete</el-button> -->
          <div class="iconbtn">
            <el-popover placement="top-start" trigger="hover" content="编辑">
              <template #reference>
                <el-icon><Edit /></el-icon>
              </template>
            </el-popover>

            <el-popover placement="top-start" trigger="hover" content="查看">
              <template #reference>
                <el-icon @click="yanjingbool"><View /></el-icon>
              </template>
            </el-popover>

            <el-popover placement="top-start" trigger="hover" content="删除">
              <template #reference>
                <el-icon @click="deletebtn(scope.row.caGradeid)"
                  ><Delete
                /></el-icon>
              </template>
            </el-popover>

            <el-popover placement="top-start" trigger="hover" content="状态">
              <template #reference>
                <el-switch v-model="value1" @change="booldata(scope.row)" />
              </template>
            </el-popover>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-model:current-page="currentPage4"
      v-model:page-size="pageSize4"
      :page-sizes="[10, 20, 30, 40]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
  <!-- 新增按钮弹窗 -->
  <div class="newdom" v-else>
    <h1>还款登记</h1>
    <div class="adddominput">
      <div class="left">
        <span>*评分等级名称</span>
        <el-input v-model="input" placeholder="请输入内容" class="input" />
      </div>
      <!-- <div class="right">
        <el-button @click="addbtn" class="addbtn"
          ><el-icon><Plus /></el-icon>新增分值区间</el-button
        >
      </div> -->
    </div>
    <!-- 表格 -->
    <el-table :data="tableData1" stripe style="width: 100%" @click="asd">
      <el-table-column prop="序号" label="序号" width="180">
        <!-- 组件插槽 -->
        <template #default="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fenzhi" label="分值" />
      <el-table-column prop="state" label="状态" />
      <el-table-column prop="name" label="状态" />
      <el-table-column prop="caozuo" label="操作">
        <!-- 组件插槽 -->
        <template #default="scope">
          <el-icon><Delete /></el-icon>
        </template>
      </el-table-column>
    </el-table>
    <div class="bottom_btn">
      <el-button type="primary" @click="nextbtn" plain>返回</el-button>
      <el-button type="primary" @click="tijiao(input)">提交</el-button>
    </div>
  </div>
</template>

<script setup>
import { ElNotification } from "element-plus";
import "element-plus/es/components/notification/style/css";
import service from "@/apis";
import { onMounted, ref } from "vue";

// 页面刷新
onMounted(async()=>{
  var res =await service.dyclink.banner_dengji();
  tableData.value = res.data.data
})

var input = ref();
var tableData = ref();
// 评分等级查询
var dengjichaxun =async () => {
  var res =await service.dyclink.banner_dengji();
  tableData.value = res.data.data
  // console.log(res);
};

// 删除列表
var deletebtn = async (data) => {
  console.log(data);
  var res = await service.dyclink.dengji_delete({ id: data });
  ElNotification.closeAll();
  ElNotification.success({ message: "删除成功！" });
  // 重新渲染
  var res = await service.dyclink.banner_dengji();

  tableData.value = res.data.data;
};
// 提交按钮
var tijiao =async (form) => {
  input.value=""
let key = {
  caGradename: form,
  caState: 0,
}
  // console.log(tijiao);
  var res =await service.dyclink.dengji_add(key);
  console.log(res.data);
    ElNotification.closeAll();
  ElNotification.success({ message: "添加成功！" });
  boolobox.value = true;
  var res =await service.dyclink.banner_dengji();
  tableData.value = res.data.data
};


/* 新增弹出对话框 */
var boolobox = ref(true);
var addbtn = () => {
  boolobox.value = false;
  // var res = service.dyclink.dengji_add();
};

// 表格内容
var caozuo = ref("XXX");
var caozuo1 = ref("123");
const tableData1 = [
  {
    name: "A",
    fenzhi: "100--91",
    state: "启用",
  },
  {
    name: "B",
    fenzhi: "90--81",
    state: "禁用",
  },
  {
    name: "C",
    fenzhi: "80--71",
    state: "启用",
  },
  {
    name: "D",
    fenzhi: "70--61",
    state: "禁用",
  },
  {
    name: "E",
    fenzhi: "60--0",
    state: "禁用",
  },
];

//鼠标滑过表格触发
// var enter = (data) => {
//   for (var i = 0; i < tableData; i++) {
//     caozuo.value = "aaa";
//   }
//   console.log(tableData);
// };
// var leave = (row) => {
//   caozuo.value = "XXX";
// };
// 分页内容
var currentPage4 = ref(1);
var pageSize4 = ref(10);

// 新增页返回按钮
var nextbtn = () => {
  boolobox.value = true;
};
</script>


<style scoped lang="scss">
.creditcard {
  width: 100%;
  height: 100%;
}
/* 顶部功能样式 */
.top_bar {
  display: flex;
  justify-content: space-between;
  .left {
    display: flex;
    width: 40%;
    height: 40px;
    justify-content: space-between;
  }
  .m-2 {
    width: 286px;
    height: 40px;
  }
  .zhuangtai {
    /* margin-left: -20px; */
    height: 100%;
  }
  .btn {
    width: 100px;
  }
  .btn1 {
    color: #4aa5fe;
    border-color: #4aa5fe;
  }
}

/* 表格样式 */
.is-scrolling-none {
  margin-top: 30px;
}
.iconbtn {
  width: 200px;
  text-align: center;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  line-height: 32px;
  cursor: pointer;
}
/* 分页样式 */
.el-pagination {
  margin-top: 20px;
  position: absolute;
  left: 50%;
  transform: translate(-33%, 50%);
}
.el-dialog {
  height: 600px;
}
/* 新增弹窗 */
.newdom {
  position: relative;
  z-index: 99;
  width: 100%;
  height: 100%;
  background-color: rgb(253, 252, 252);
  .adddominput {
    display: flex;
    justify-content: space-between;
    padding: 30px;
    height: 30px;
    .left {
      display: flex;
      span {
        color: #333333;
        font-size: 14px;
        min-width: 120px;
        line-height: 30px;
      }
      .input {
        min-width: 250px;
      }
    }
    .right {
      .addbtn {
        color: #4aa5fe;
        border-color: #4aa5fe;
      }
    }
  }
  .bottom_btn {
    // display: flex;
    position: absolute;
    right: 100px;
    bottom: 10px;
  }
}
.el-button--primary {
  height: 40px;
  width: 100px;
}
</style>